Skip to main content

Full text of "The Home Computer Advanced Course 42"

See other formats










# 
Ee 
ey 
dee aie Bis 
ae 
ie 


SRE Sacaae 
Se a 


Bie ees 
peas 


Sa 
SRE 

ses 
23 


ag 
_. 

3 By pauaaiet 
7 


7 
co 


ee es 


Re 
coe 


he 
fee ays 


ES 


s 
t BS 


eS 


are ce 
ace 


cy 


L 


estes § 
Bae 
as 


eB 





ee 


. : 
aL 

eats Bs ox seats ee Cs BRekoRaRs e Ate 4 
bt. | of : 
: . og . oo 
skal eapaeaeaene fy « ® : carga “8 ¥ 
SS SS | RS : ee : : 


a 


See 


3 
ee 


RENIN“ Raa 








FITTING THE BILL We examine a | 
number of products currently on the market 8? 
that are billed as ‘robots’ and see how well 
they conform to our definition of the term 





A TOUCH OF CLASS The Touchmaster is 
a new graphics tablet that is designed to work 83 
with most of the popular home machines. 

We see how it compares with its rivals 






Bs 
= sai 


EDUCATED GUESS We conclude our 
look at TK! Solver by looking at its ability to 
solve equations from incomplete 
information through a series of ‘guesses’ 
















oe 


WHO D ND IT? Using the example ofa 


murder mystery in which a list of suspects is 83? 
drawn up and analysed, we continue to 
examine the use of list processing in LOGO 






RARER 


NFORMATION STORAGE AND — 
RETRIEVAL TO INKJETPRINTERA 8 
weekly glossary of computing terms 











PROGRAMMING PROJECTS 


TAKING ORDERS Now that we have 
discussed methods of moving around the 876 
adventure world, we can look at how the 

program analyses instructions from the player 


00000000 


























TSS BONES POET PTET Se ORO RO NETS 


YTE THE DUST Our debugger program 
is now complete and this instalment also 8 
concludes our series on 6809 machine code 


OUTBOARD MOTOR We look at the 

working principles of the stepper motors that B35 
will be used to power the robot we are 

building and construct the board to hold the 

motor and accompanying parts 








REFERENCE CARD We begin to list INSIDE 
extracts from the 6502 programmers’ BACK 
reference card | COVER 


COVER PHOTOGRAPHY BY CHRIS STEVENS ROBOTS COURTESY OF ROBOTICS WORKSHOP 














FITTING THE BILL 








As we continue our series on the topic of 
robotics, we examine some of the products 
sold commercially under the name ‘robot’ to 
see if they fill the role expected of them, and 
if they fit our carefully constructed 
definition of the term. 





Up to this point in the Robotics series, we have 
dealt primarily with theoretical considerations of 
robot design and operation. In practice, many of 
the concepts discussed have not _ been 
implemented, or are restricted by a lack of 
funding, intricate mechanical parts, and/or 
intelligent software. Existing robots, whether they 
are intended for home or industrial use, tend to fall 
short of what we have come to expect of robots 
over the years. Sensors exist to make a robot see, 
hear, or feel, but as yet the sensations the robot 
experiences have no meaning for it, and cannot be 
synthesised to stimulate the robot to original, non- 
programmed behaviour. Robbie the Robot and 
his other fictional counterparts are still a long way 
from reality. 

Nevertheless, many products are now being 


Spot The Robot 


sold under the name ‘robot’. These range from 


small toys for under £1 to vastly expensive R2D2 


lookalikes and industrial robots. After examining 
the components of robot design and theory for 
several instalments, we must now consider what 


constitutes a true robot. We must not be too 


demanding, but we should be able to take what we 
know and apply it in a workable definition. 

The first consideration, and one that eliminates 
many of the lower-priced ‘robot’ products, is 
movement: can the robot move about a space by 
itself? We cannot expect the robot to program 
itself, or to set a course of action without human 
guidance, but we can expect a robot, once set in 
motion, to be able to operate independently of 
continuous human control. Without this freedom 
of movement, an object cannot be considered a 
robot. : 7 | 

Having passed the test of movement, our robot 
candidate must now be evaluated on the basis of 


how the movement is effected. A small toy car can 


be given a motor and batteries that keep it moving 


in a straight line. Add bumpers to it, and the car 


can turn away from obstacles such as walls and 
tables. Give the car a slightly unusual centre of 


Our Robot 

Powered and controlled from its 
parent computer, the robot is 
equipped with touch- and light- . 
Sensitive sensors 


SS 


Big Trak 

LOGO-like distance and 
direction instructions can be 
programmed into this 
microprocessor-driven device 
through its keyboard 


a 
=e =) 


Bumper Car 

This battery-powered toy will 

run ina straight line until it hits 

an object, in which case it will 
turn clockwise 90° and continue 





STEVE CROSS 


Amazing Tracks 

The three devices are 
attempting to run a maze: the 
toy car simply blunders from 
wall to wall, Big Trak follows its 
human operator’s programmed 
instructions for running the 
maze, while our robot learns the 
maze through the interaction of 
its software and sensors. We 
can be sure that the robot will 
solve the maze eventually, no 


matter what happens; Big Trak 3 


will follow its program, so may 
solve the maze if the operator's 
directions are correct; the toy 
car could solve only ‘right- 
handed’ mazes, and then only 
by chance. ! 

When the car collides with 
Big Trak, the car is unaffected 
since its behaviour is 
purposeless; Big Trak, however, 
is diverted 90° off its course 
(shown in green) but continues 
to turn and travel as if it were 
still on track (Shown in red). 
Both devices react 
unintelligently to this 
unforeseen event where the © 
robot would treat it as just one 
more aspect of an unpredictable 
environment 


THE HOME COMPUTER ADVANCED COURSE 821 

















2y 


9009000 
oO 


\ e) 




















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































ROBOTICS, APPLICATION 






















































































































































































































































































































































































































































































































































































EDUCATED GUESS — 





examination 0 
TK!Solver an equation processing 
program for the Apple Il, IBM PC and 
compatibles, and the ACT Apricot — with a 
closer look i i ilities. 














As we explained in 

spreadsheet series (see page 804), TK!Solver is a 

‘next generation’ software package that takes the 
concept of the spreadsheet into the realm of higher 
mathematics and engineering. We have already 
shown that TK!Solver lets the user define 
variables with names and use these in complex 
mathematical equations. In this instalment, the 
last of our spreadsheet series, we look in detail at 
TK!’s unusual ability to iterate. This is a method 
where the program can solve for a variable by 
guessing at it. Ordinarily, when working with 
equations, one can determine the values of all the 
variables if enough information is given from the 


outset. The program simply reduces the problem | 


to a series of calculations. For example: 
A? + B = 2C0S Y 


can easily be solved for any of the three variables if 

the other two values are known. Faced with this 

equation — and given values for A and B — TK!s 

Direct 
calculations and output a value for Y. 

- But there are occasions when the determination 

_ ofavalue is not straightforward. One such case is a 

redundant equation, which defines a variable in 
terms of itself. For example, consider: 


D=(A+B)/(2*D) 


within a model where A is the only known value. 
Other problems can occur as the result of an 
incomplete model, or a model with many 
interdependent variables and a limited amount of 
data. The concept of iteration is a difficult one, so 


let’s look at a more practical example of iteration. — 
Let’s reconsider the car journey model created — 


in the last part and add a few details to make it 
more applicable. As you will recall, the previous 
model was built around five values: distance, time, 
speed, fuel and mileage. It could calculate 
mileage, given speed and fuel consumption; 
distance from speed and time; and several other 
simple variations. What if we now want to 
determine how fast we should travel in order to 
complete a trip within a given budget? 

To begin with, we must add several factors to 
our model. For instance, the model must take into 
account the power output of the vehicle, the 
internal friction of the engine and wind resistance, 


824 THE HOME COMPUTER ADVANCED COURSE | 





Solver would perform the required: 


rae 


all of which will have an effect on the vehicle’s 
mileage and speed. (We will assume that internal 
friction is constant.) We must also have an upper 


boundary for our budget, and the cost of the fuel 


being consumed. | 7 

We'll begin building the actual model by 
entering these equations in the Rule sheet, one 
equation to a line. These equations are read 
automatically into the Variable sheet: _ 


Building Equations 


Because there are several variables, the screen is 
too small to hold all the information. To see all the 
variables displayed, we can show the Variable 
sheet in a window by itself. We do this by pressing 
the semi-colon key (;) to move the cursor into the 
variable window, and then type in W1. Now all the 
variables can be seen and we can begin entering 
values for them. _ 


DIRECT SOLVING 


The model can be solved directly, if enough | 


information is given at the start. For instance, 
enter the following values in the INPUT column: 


Input Values For Direct Solver 








IAN McKINNELL 























~~ 


& 
























Then press ! to perform the calculation. TK! 
displays the message Direct Solver, and the 
unknown values appear in the OUTPUT column, as 
shown: ; 


Direct Solver Results 


This gives us a nice breakdown of all the 
information we want. But what if we want to use 
this model to solve a problem with less 
information given at the outset? Let’s consider a 
calculation where we have a maximum budget of 
£50 to spend on fuel for a 1,000 mile trip. We 
know the price of fuel (say £1.75 per gallon) so we 
can easily determine how much we can spend per 
mile. It might be more difficult, however, to 
determine what speed we need to travel in order to 
achieve the mileage needed to complete the trip 
within our budget. 

We begin by blanking the values already 
entered. We do this by typing RVY (for Reset 
Variables Yes). Then we type in the information 
that we know: 1000 for distance, 50 for cost, and 
1.75 for price. We use a value of 1/3 for internal 
friction (which TK! evaluates to 0.333333) and 
0.0000095 for wind resistance. Press ! to calculate 
and the following values appear: 


Incomplete Model 


Note that no values have been generated for 
speed, time or power — and speed is the specific 
value we need. If we shift the display from the 
Variable sheet to the Rule sheet, we will see that 
three of our equations remain unsatisfied (which is 
indicated by the * in the Status column): 








Unsatisfied Equations 





ITERATIVE SOLVER 


Since we cannot solve the model using the Direct 


Solver, we must try the Iterative Solver. This takes a 
starting value, input as a guess, and fits it into the 
equation. If the value is not correct, TK!Solver 
uses a series of successive approximations (like the 
game of ‘higher’ and ‘lower’) to pinpoint the exact 
value. | 

The first thing we do is take the mileage value 
generated previously and move it into the Input 
column to give TK! one extra value to start with. 
We do this by typing | in the Status column next to 
mileage on the Variable sheet. Then we estimate a 
value for speed — say 50 — enter that number in 
the Input column, type G for guess in the Status 
column and press ! to calculate. TK! displays 
Iterative Solver at the top of the screen and counts 
off each approximation. On the fourth attempt, 
TK! arrives at the correct value for speed, time and 
power, as shown: | 


Hterated Values 


According to TK!Solver, an average speed of just 
over 47 miles per hour is needed to complete the 
trip within our budget. The closer a guess is to the 
actual value, the sooner TK! finds a solution. 
TK!Solver is available from Practicorp for the 
Apple II, IBM PC and compatible machines, and 
the ACT Apricot, for £195. Software Arts also 
publishes ‘Solver Packs’ at £95 each with 
predesigned models for specific applications. 


THE HOME COMPUTER ADVANCED COURSE 825 








~ TAKING ORDERS 





Up to this point in our adventure game 
programming project, we have discussed 
methods of map making, formatting output 
and moving around the adventure world. In 
this instalment, we show how the program 
analyses and obeys instructions given to it by 
the player. 








826 THE HOME COMPUTER ADVANCED COURSE 





Adventures are usually constructed so that the » 


player can move from location to location, picking 
up and dropping objects along the way. A set of 
commands allows the player to perform these 
simple tasks. The commands we have used are: 





Variations on these may also be available, such as 
MOVE instead of GO, or GET instead of TAKE. Part of 
the fun of playing an adventure game is to 
determine what words the game will accept. For 
example, a player might try the command SWIM 
when in a dry location. If the program responds by 
telling the player that he cannot swim here, then 
the player could reasonably assume that there 
are locations where swimming is allowed. 
(Alternatively, the programmer might just want 
the player to think that!) 

The number of commands accepted by a game 
varies according to the complexity of the game and 
the amount of effort the programmer has made to 
cover every eventuality. The most important thing 
for the designer to do is to make sure the program 
does not crash if a player tries to enter a command 
that is not catered for. A failsafe routine that prints 
‘I don’t understand’ may be all that’s required, 
bearing in mind that some flexibility should be 
added so that players can enter commands in 
different ways. For example, it would be annoying 
for a program that accepts the command TAKE 
LAMP to respond to,the command TAKE THE LAMP 
with ‘I don’t understand’. Adding flexibility will be 
discussed at greater length later. For the moment, 
we need to look at the type of instructions that 


might be given during the game, and devise a 


routine that will break these down into a form that 
can be easily interpreted. 


COMMAND SPLITTING 


No matter what the instruction is, it is very likely 
that it will be phrased in the imperative — such as, 
GO SOUTH TOWARDS THE RIVER or KILL THE ALIEN. 
The advantage of this sentence structure is that it is 
easy to break down: the verb always comes as the 
first word in the sentence, the object of the verb 
follows this, and finally there may be some form of 
qualification of the action. A first stage in the 
analysis of a command is to separate the verb from 

















the rest of the sentence. This task can be easily 
achieved by scanning through the sentence one 
character at a time, using MIDS, until a space is 
found. The part of the sentence that lies to the left 
of the space is the verb, and can be assigned to the 
variable VBS. The part of the sentence to the right 
can be assigned to a second variable, NNS. This 
subroutine is used in Haunted Forest to split the 
instruction assigned to the variable ISS: 


256@ REM *xx**x SPLIT COMMAND S/R *2%«x% 

25190 IF ISS="LIST”" OR IS%="END" THEN ¥VBS=1S$!:F =12RETURN 
P5515 IF IS#="LOOK" THEN V¥VBS=IS#$:iF=1:5RETURN 

2520 F=8 

P3538 LS=LENCISS> 


. 2340 FOR C=i TO LS 


25580 AS=MIDSCIS$,C,13 

e568 IF AS<>" " THEN 2599 

2578 VBS=LEFTSC(IS$,C-1):5F=1 

2588 NNS=RIGHT#(IS$,LS-C)IC=LS 

25969 NEXT C 

e6baa : 

261@ IF F=i1 THEN RETURN 

2620 PRINT:PRINT"I NEED AT LEAST TWO WORDS” 

2630 RETURN 

Before the routine attempts to split up the 
sentence, it first checks to make sure that the 
command is not one of the three possible single- 
word instructions — that is, LIST, LOOK or END. If it 
is a single-word command, then the complete 
instruction is assigned to VBS, and the routine is 
exited. If the command is not one of these, then the 
routine enters a FOR...NEXT loop and begins to 
scan for the first space. Two techniques used 
within this loop need special mention. Both relate 
to the fact that it is extremely bad programming 
style to perform a conditional jump out of a 
FOR...NEXT loop without passing through the 
NEXT statement. Instead, to signal the fact that 
some condition has been met — in this particular 
case, that a space has been found — a flag, F, is set 
to one. Secondly, when the first space has been 
found, it is a waste of time to continue scanning 
through the rest of the sentence. 

The loop can be neatly terminated at this point 
by setting the loop counter, C, to its upper limit, LC. 
Consequently, when the program again reaches 
NEXT, it will pass on to the following instruction, 
rather than loop back to the FOR statement. Once 
the ioop has been correctly terminated, then the 
status of the flag, F, can be tested. A flag value of 
one indicates that the sentence consists of more 
than one word, and ail that remains to do at this 
stage 1s to return to the main loop. If the flag is not 
one, then the command has only one word 
and is not one of the single-word commands tested 
for earlier. In this case, a message stating that two 
words are required is printed before returning for 
another command. | 


NORMAL COMMANDS 


For the main part of the program, the player will 
simply move from location to location and pick up 
or drop objects that may be found. Therefore, for 
the majority of locations, the commands GO, TAKE, 
DROP, LIST, LOOK, END — and their variants — are 
sufficient to allow the player to do this. Only in 
unusual circumstances will the player wish to use 
other more specialised commands. For example, 
there is little point in using the command KILL if 





there is nothing present to kill. We can, however, 
devise a program structure where, on the majority 
of occasions, only the six commands associated 


- with movement and objects are tested for. When 


the player enters a new location, the program can 
test to see if it is one that has been designated 
‘special’ in some way. If this is the case, then any 
new command requirements can be dealt with bya 
specific command subroutine for that particular 
location. Therefore, the main calling loop to our 
program should do the following: 


1) Describe the location and list the exits. 

2) Determine whether the location is ‘special’. 
3) Ask for a command and, if the location is not 
special, scan the list of normal commands. 


There must also be a facility in the main loop to 
distinguish between a command that causes a — 
move to a new location and one that does not. In 
the first case, the loop needs to go back to the 
beginning of the loop to describe the new location | 
and decide whether or not it is special.-In the 
second case, it is necessary only to loop back to ask 
for a new command. The simplest way to 
implement this is to use a ‘move flag’, MF, which is 
normally set to zero. If a command involves 
movement then this flag is set to one. The status of 
MF can be tested at the end of the main loop and 
the appropriate jump made. Add the following 
lines to Haunted Forest: 


27@ GOSUBESOO=REM SPLIT INSTRUCTION 

275 IF F=0 THEN 260:REM INVALID INSTRUCTION, 
2386 GOSUB3S@08:REM NORMAL COMMANDS 

296 IF VF=@ THENPRINT:PRINT"I DONT UNDERSTAND” 
30@ IF MF=1 THEN 246:REM NEW LOCATION 

3160 IF MF=-@ THEN 266:REM NEW INSTRUCTION 


3000 REM *x** NORMAL COMMANDS S/R «**% 

3010 VF=8:REM VERB FLAG 

3020 IF VBS="GO" OR VBS="MOVE" THENVF=1:!GOSUB3500 

3039 IF VB$="TAKE" OR VBS="PICK"THEN VF=1:GOSUB3790 

3040 IF VBS="DROP" OR VBS="PUT"THEN VF=1:GOSUB3900 

3050 IF VB$="LIST" OR VBS="INVENTORY"THEN VF=1:G0S 
UB4 100 

3055 IF VB$="LOOK" THEN VF=1:MF=1:RETURN 

3068 IF VB$="END" OR VBS="FINISH" THEN VF=1:GOSUB4 
178 2 

3078 RETURN | 


In the first routine, another flag, VF, is used to 
indicate whether or not the verb has been 
understood and obeyed. Only when the verb has 


been isolated is VF set.-to one. We can insert a 
failsafe ‘I don’t understand’ statement in the main 


loop by testing the status of VF. If VF remains zero 


then the verb in the command has not been 
recognised by the analysis routine, and the 
statement is displayed. 

In the next instalment of the project, we will 
deal with subroutines for picking up, dropping and 
listing objects. For now, we can add a short END 
command subroutine to our group of normal 
commands: 


4176 REM x*xex*x END GAME SYR **%x 

4180 PRINT:PRINT"ARE YOU SURE (Y/N) 7" 

4196 GET ASI IF AS<C>"Y" AND AS<>"N" THEN 4198 
$2698 IF AS="N" THEN RETURN 

94216 END 


The LOOK command is also straightforward. To 
redescribe the current position, we simply need to 
set the ‘move flag’, MF, to one and return to the 
main program loop. Setting MF will cause the main 


-THE HOME COMPUTER ADVANCED COURSE 827 





\ 


RETURN 


THEN NN@=hie! 1=LN 


THEN NNS=LH: IT =LN 


C=1 


THEN NEXT I 
+1 
="EAST" 
="WEST" 


LEN (NN?) 
# 
C= 


We Sap he 

Cd: 
CR WS 
OR LE 


I 


ion words sought until a match is 


LN 


1 TQ LN 
I 
Cc 


="NORTH" 


= 
= 
F 
* 


a 


direct 
= "SOUTH" 


NN#+" 


MIDS CNN& 


= 


s 


645 FOR I 
3656 IF MIDS CNNS 


3630 REM *x*x** SEARCH FOR OIRECTION S/R ERE 
3655 WS 


the four 
found 
3646 NNS& 
36660 IF WS 
3665 IF We 
3678 NEXT I 
3675 RETURN 


3 


g 
ts. 
t 


ca 
S 
is no 
ocati 
if, 
ions 


changed by the LOOK command, the same! 
Th 
the player has performed a series of 


will 


its exi 
e 
on 
after 
, the 
has 


act 


g, thus 
d 
on of the current location 


iable 


command is useful 


1S 
ADDING FLEXIBILITY 


cribe a location an 


ed 


es that des 
the value of the location v. 


routin 
al descripti 


be describ 
moved off the screen 


origin 


program to loop back to the be 


the 
As 


/ 


ooo00000 0 


90000000 
is 





ect we developed a 


e proj 


To add th 
e we need 


instalment of th 


In the last 


ew routine to the 
imply to add the 


isn 


ne 


routin 


tt 


movement rou 


the player 


different forms of the 


g movement commands, 


issuin 


e 


When 





S 


>) 


ent 


ORTH following line 


same movem 


may type in 


ins 


, MOVEN 


GO NORTH 


b 


ample 


on. For ex 


tructi 


a D 
= 
Sos 
oO 
~~ ) O& 
OW ry 
ase o 
: OR 
rf peweed 
n- 
zy er 
o Ltd 
- £€x5 
» Pas 
« 20O¢ 
no eae oe 
eo fa SO 
tS — ce 
e to 
o Sa 
ie = oe 
w bo © & 
f #Ss 
to 3 8 
© ean iD) 
it) NM. 
2 2 ae 
o £20 
a esa 
B hes 
in Awe Vs 
a aS 
¢") 2 8°32 
oor oH 
= 3 
pEeuS 
Se Bp 
Soeas & 
on =o G a» 
A m= 
SELLE 
4 eae 
CS Oom'™ 6 
om Og 
bad Send q 
SBaes 
aoe on SD 
Cpe 5s 
OobEeES 
a & o) 3 
= a2) of 60. 
ie ie 
Bae > 5 
ZeGas 
© ° 
= Shee 
Fagan? 
bon 
Bogs 
ep 0 O 
Zea § 
SS hee 


OH og BCDO DOW 
Sepgecagse 
SO, 5 ¢ Sues 
Se a25 Ra 05 
shOos S2EE 
Se aea* 3 ho 
ZBESoenwERUH= 
oO Sige. gs 
S2P85 2595 
5 oO sSa2o- 
mae Oy hos o 
B Oe a op OP 
4S e&O 8 
asses & 55 
= 9 8 - BZ 
Soh sey 8s 
wSegseeaes 
Beene an 
© @ DY & Men) roe) bed 
Bey > AS 4?) ae we 
2 on ooger= 
ae ee oe OO. 
oOG5 3 0 2 
zs ce & 
5 See bE LD 
SsReea0naqgzc OE 
Of omg ORS 29 
SELES LS6SZsSS 
Onna soo yo 
a “meee ss 
oa DO O'S 
oR? RS. ar 
> = 2S aD) ou N oD 
Sh 3 Oo eS 
ga or eR. e 
BSR et ES a 
2 cSSU EE 
F]asP ro gd 
os SHEER Y 
Spesa” ’ se 
Sm ag k US 
ES -vses 
Syeeagros 
) Ro S 
Ssvosevts 
eaegag” : 
23 hg oe 
FE Sore SES 
> N 5) * ai end 
Peo bees 
Roe Sis d 
0 D) = Fp) ove) 
EEERoMvE 
=S=Sov gE os 
ates B= -=yc 
RPeaeees 22 


ed as N for NORTH. 


would be accept 














828 THE HOME COMPUTER ADVANCED COURSE 


sa 





INFORMATION STORAGE AND 
RETRIEVAL 


Information storage and retrieval’ is the term used 
for the accessing and retrieval of information from 
a magnetic medium such as disk, tape or — in 
older systems — cards or punched tape. This 
information may be in the form of files, programs, 
data or graphics. It is necessary to use a storage 
medium that will not only retain the information 
when the power is switched off, but also allow the 
computer to read the information back in at some 
other time. This means that a computer must have, 
or be attached to, an interface that can read and 
write the data. Thus information storage and 
retrieval has come to mean not only the process of 
reading and writing information, but also the 


techniques involved in such a process. 


INFORMATION TECHNOLOGY 


In one sense, information technology has been 
around for thousands of years: hieroglyphics, the 
abacus, the quill pen and the printing press are all 
examples. In the last decade or so, following the 
development of microelectronics and_ the 
subsequent dramatic fall in the price of such 
circuitry, information technology (IT) has come to 
mean the electronic storage, transmission and 
processing of information — specifically with 
reference to computers, video and 
pager es As such, IT has already had 
a profound effect on much of the world’s 
population, and most major organisations are now 
dependent on computers. An enormous amount 
of effort and resources is currently being put into 
information technology. The world now depends 
for its communications on satellites, such as 
COMSAT, while other satellites constantly 
monitor every inch of the world’s surface. 


INFORMATION THEORY 


Information theory (developed by Claude 
Shannon at Bell Laboratories, New Jersey, in 
1948) is the area of computing that investigates the 
transmission of data. It involves the examination 
of newly-arrived data and whether it tells us 
something new — that is, the extent to which it 
reduces the uncertaintyin the information system. 
Thus, information theory consists of the study of 
the nature of the information and its speed of 
arrival. In its simplest form, this restricts 
information theory to the rate at which new 
information arrives, and from which channel or 
source. 

However, in a wider sense, information theory 
can include such areas as coding theory. This 
discipline covers the translation of data from one 
form to another, and how this can be 
accomplished efficiently without any loss of the 
information being transmitted. 


INITIALISATION 

Primarily, initialisation is the process performed 
by the computer’s ROM-based operating system 
when the machine is switched on. This involves 


default values being placed in the registers and 
various addresses in memory. Typically, during 
initialisation, a microcomputer will set the stack 
pointer, clear the decimal mode and initialise the 
various input/output devices. This initialisation 
will also set the top and bottom of memory 
pointers and the zero page. Finally, initialisation 
includes the setting up of the initial screen display 
and the screen editor variables. 


Initialisation has a second meaning: the 


formatting of disks. This takes the form of writing 


the track that will contain the disk directory. The 
information written on this track is the disk’s title, 
the block availability map (BAM) and a list of 
markers for each track on the disk. 

Initialisation can also be performed by 
programmer. If a program is to be properly 
structured, variables should have initial values 
assigned to them at the beginning of a program. 
This is often termed the ‘initialisation procedure: 


INK JET PRINTER 


An ink jet printer forms characters by squirting 
droplets of ink from a nozzle at the piece of paper. 


Although these printers were developed in the 


1960s, it was not until the mid-1970s that their use 
became widespread. 

There are two types of ink jet printer. The 
pulsed jet printer consists of either one or a 
number of nozzles, which fire several droplets to 
produce a single dot on the paper. By arranging 
these dots in patterns, characters can be built up — 
in much the same way as a dot matrix printer forms 
its type. If a number of nozzles are fitted to the 
print head, then the user has the possibilty of 
multicolour or higher resolution printing. 

The other type of ink jet printer is known as the 
continuous stream printer. As its name suggests, 
this printer shoots a continuous jet of ink at the 
paper. The droplets in the stream are electrically 
charged as they leave the nozzle, and then pass 
between charged electrodes, which alter the 
direction of the ink stream. The droplets of ink are 
directed to a precise position, and the character is 
drawn in much the same way as a pen stroke. 








STEVECROSS 








A Drop In Quality 

Ink is fired at the paper through 
a nozzle that breaks the stream 
into separate droplets. These 
are electrically charged, which 
enables the metal deflector 
plates to direct them into 
character patterns on the paper 
— the electron beam ina 
cathode ray tube is moved 
around the screen in exactly the 
same way 


THE HOME COMPUTER ADVANCED COURSE 829 


IAN McKINNELL | 


~ ATOUCH OF CLASS — 


} The Touchmaster Pad 


The sheet provided with the 
software simply slots into the 
drawing area. By pressing the 
appropriate command on the 
right-hand side of the overlay 
and moving the pencil, stylus or 
finger to the drawing area the 
command will be executed on 
the screen 


830 THE HOME COMPUTER ADVANCED COURSE 








as aids in the construction of graphics 
displays. The Touchmaster graphics tablet is 
unique in that it may be used with most of 
today’s popular home computers and, so the 
manufacturer claims, can also be used as a 
simplified replacement keyboard. 


Today’s best-selling computers all support high- 
resolution graphics displays. However, unless 


ready-written graphics software is available, much 


time and effort is required to create such displays 


and many features are not fully utilised. A ‘sketch’ 


program is not sufficient because the user will 
often wish to copy an existing image into the 
computer instead of simply drawing freehand. 
Several digitisers have been marketed for this 
purpose, but these have mostly been designed for 
use with specific machines, such as the BBC Micro 
or ZX Spectrum. The Touchmaster graphics 











Many different devices have been marketed | 


tablet is designed to work with a wide range of 
home machines (some of which will require a 
suitable interface or cable). This device is also 
being promoted as a replacement keyboard, but 
the simplicity of its design means that such use is 
restricted to selection between a number of menu 
options or for simple.games control. A computer 


keyboard 1s still required for data entry, as well as 


for loading the Touchmaster software itself. 

The Touchmaster is fitted in a neat grey case 
measuring 350 by 330 by 35mm. The back of this 
is slightly raised, forming a convenient angle for 
drawing. A plug-in transformer is supplied, with a 
single red LED indicating when power is on; 
however, no on/off switch is fitted. To allow the 
tablet to be used with a wide range of home 
machines, both serial and parallel interface 
sockets are fitted to the rear panel, together with a 
socket — not mentioned in the manuals — for a 
foot switch. In fact, the manuals are barely 
adequate: the hardware manual gives instructions 
on the connection of the tablet and provides a 
number of simple BAsic programs for reading co- 
ordinates, but is insufficiently detailed. 

The tablet relies on the membrane technology 
that was developed on the ZX81 and Spectrum 
keyboards, and provides a 256 by 256 pixel 
resolution. The upper layer is separated from the 
lower resistive film by an insulating mesh, and 
pressure on the upper layer forces it to make 
contact with the film. The tablet contains a 
microprocessor that scans the top film in one 
direction while scanning the lower layer in 
another, and the co-ordinate of the ‘contact point’ 
is then sent over both serial and parallel interfaces. 
The serial interface is used to connect the tablet to 
the BBC Micro, while the parallel interface is 
required for use with the Commodore 64, Vic-20, 
Spectrum and Dragon. The ‘Touchmaster’s 
resolution is less than that provided by many hi-res 
screen displays, so BBC Micro owners, for 
example, will be unable to resolve to a single pixel 
in Mode 0. 


MULTIPAINT PROGRAM 

A drawing program called Multipaint is supplied 
with the ‘Touchmaster. This provides a 
demonstration of the facilities provided, but is 
hardly a comprehensive graphics aid. A plastic 
template gives a menu of the facilities available, 
with the selected option displayed in a ‘status’ 
window at the bottom of the screen. Five different 
brush types may be used; each of these can be any 
width from two to 32 pixels, in steps of two pixels. 
The window also shows the current drawing mode 
— Dots, Points or Freehand — and the selected 





xR | _ ; 


re 












































foreground and background colours. Colours may 
be changed by pressing the required option on the 
menu until the desired choice appears in the status 
window. : 2 

Once the correct colours and brush types have 
been selected, further options are avilable for the 
creation of boxes, circles, polygons and ‘rubber- 
banded’ lines. A stylus is supplied with the 
package, but finger pressure may be used instead. 
The Touchmaster, with its larger tablet area, does 
not suffer from the same restrictions as the Koala- 

pad (see page 629): pressure from a finger may be 
translated into a precise co-ordinate rather than a 
mere approximation, so electronic finger-painting 
is a real possibility! 

Unfortunately, Multipaint offers no more than 
rudimentary features. A FILL option is marked on 
the template and documented in the manuals, but 
— on the Spectrum version at least — this does not 
appear to operate in the expected manner. Neither 
is there any facility for magnification or editing, 
which means that colours may not be changed. On 
the Spectrum, where it is often easier to draw in 
black and white before adding colour, this is a 
decided disadvantage. 

As a piece of hardware the Touchmaster tablet 
appears to have a lot going for it compared with 
rivals like the Grafpad and the Koala-pad. It is : 
robustly built and offers a full A4-sized drawing 
area that can be connected to most of the more 
popular home computers. One § significant 
advantage is that if you decide to upgrade or 
change your machine in the future, all that is 
required is a new interface — plus the appropriate 
software, of course. 

It is a disappointment that the documentation 
and software supplied should be so poor 

-compared with the standard of the tablet itself. 
Touchmaster is bringing out a range of software 
designed specifically for use with this tablet; | 

_ although the real proof of success will come if | 
independent software houses decide to support it. ! 








THE HOME COMPUTER ADVANCED COURSE 831 


WHO 
DUNNIT? © 








Our s series s of investigations into the u use e of 
LOoGO’s list processing facilities continues 
with a look at how to set up a simple 
database. We use the example of a murder 
investigation, in which a list of suspects is 
created and then analysed to ascertain who 
| the murderer v was. | 








community in the Ozark Mountains. eatich 
has been viciously attacked with an axe and killed. 
We know that Matthew and Joshua both own 
axes, James and Ebenezer own guns, and cousin 
Jane has a knife. Matthew and James both had 
blood on their hands when they were questioned 
by the local sheriff. 

Our LoGo database of information about this 
crime will consist of a list of facts — each of which 
consists of a relation, together with one or more 
nouns. When represented in LOGO, one fact is 
[OWNS MATTHEW AXE] or, in English, ‘Matthew 
owns an axe’. To represent the fact that James had 
blood on his hands, we use [BLOODY JAMES]. 

We begin our investigation with an emply 
database: 


 TOSETUP | 
MAKE “DATABASE [] 
END 


We then add facts to our database as we discover 
them (providing they are not already in the 
database). For example, we would input ADD 
[OWNS JANE KNIFE] using the following ADD 
_ procedure: 


TO ADD :FACT 
IF NOT MEMBER? :FACT :DATABASE THEN 
MAKE “DATABASE FPUT :FACT :DATABASE 
END | 


The database will eventually fill up: 


[[BLOODY MATTHEW][BLOODY JAMES][KILLED 
ZACHARIAH AXE] [OWNS MATTHEW AXE] 
[OWNS JOSHUA AXE] [OWNS JAMES GUN] 
[OWNS EBENEZER GUN] [OWNS JANE KNIFE]] 


To print out the database use SHOW. This can be 
followed by either “ALL, in which case the whole 
database will be printed, or by the name of a 
relation, in which case only the facts for that 
relation are printed. So, SHOW “OWNS will show us 
who owns what. 
TO SHOW :S 
IF :S = “ALL THEN LIST.ALL :DATABASE 
LIST.REL :S :DATABASE 
END 


832 THE HOME COMPUTER ADVANCED COURSE 





TO LIST.ALL :LIST 
IF EMPTY? :LIST THEN STOP 
PRINT FIRST :LIST 
LIST.ALL BUTFIRST : LIST 
END | 
TO LIST.REL :S :LIST 
IF EMPTY? :LIST THEN STOP | 
IF :S = FIRST FIRST :LIST THEN PRINT FIRST 
“LIST 
LIST.REL :S BUTFIRST :LIST 
END 


Now we must devise ways of querying the 
database. The simplest kind of query we might 
make of our database is to check whether a fact is 
known to be true. This we do with a procedure 
called DOES, which checks whether a fact is in the 
database. For example, DOES [OWNS JANE KNIFE] 
should give the answer YES. 


TO DOES :FACT 
IF MEMBER? :FACT :DATABASE PRINT “YES 
ELSE PRINT “NO 
END 


It would be much more useful for our investigation 


into this terrible murder if we could ask questions 


such as “Who owns an axe?’. The way we will deal 
with this is to use ‘variables’. Any word whose first 
character is ? will be assumed to be a variable. We 
can then paraphrase the question as: __ 


WHICH [OWNS ?SOMEONE AXE] 


The reply to this will be a list of all possible values 
of the variable ?SOMEONE that are consistent with 
the information in the database. 


[?SOMEONE MATTHEW] 
[?SOMEONE JOSHUA] 
NO (MORE) ANSWERS 


We can have multiple variables. For example: 
WHICH [KILLED ?MAN ?IMPLEMENT}] 


will give the answer: 


~ [?MAN ZACHARIAH] [?IMPLEMENT AXE] 
~ NO (MORE) ANSWERS 


_ Let’s consider the procedures that enable this 


analysis of the database, individually. WHICH 
passes the job over to FIND, indicating DATABASE as 
the source of facts. 


TO WHICH :QUERY 
FIND :QUERY :DATABASE 
PRINT [NO (MORE) ANSWERS] 
END 


FIND sets up two global variables, VARS and ANS: 
VARS is used to hold each possible set of values of 
the variables in the question, and these are 
collected together in the list ANS. 


TO FIND :QUERIES :DATA 
MAKE “VARS [] 
MAKE “ANS [] 
COMPARE :QUERY :DATA 
PRINTL :ANS 

END 








COMPARE looks at each fact in the database in turn. 
If there is a match then the new set of values in 
VARS are added to ANS before setting VARS back to 
the empty list. COMPARE then continues working 
through the DATABASE to see if there are any other 
possible matches. 


TO COMPARE :QUERY :DATA | 
IF EMPTY? :DATA THEN STOP 
IF MATCH? :QUERY FIRST :DATA THEN MAKE 
“ANS FPUT :VARS :ANS 
MAKE “VARS [] 
COMPARE :QUERY BUTFIRST :DATA 
END 


To see what MATCH? does, consider the case where 
the inputs are [OWNS ?SOMEONE AXE] and [OWNS 


JOSHUA AXE] in response to which MATCH? outputs - 


TRUE and sets VARS to [?SOMEONE JOSHUA]. If the 
inputs are [OWNS ?SOMEONE AXE] and [KILLED 
ZACHARIAH AXE], then MATCH? outputs FALSE. 

The real difficulties arise, however, if there is 
more than one variable involved. VALUE? is used to 
check if the variable has already been assigned a 
value for that fact in the database. 

We have used here an alternative notation for 
conditionals in Loco. TEST evaluates a condition. If 
the result is true then the actions following IFTRUE 
will be performed, otherwise the actions following 
IFFALSE will be carried out. 


TO MATCH? :QUERY :FACT 
IF ALLOF EMPTY? ‘QUERY EMPTY? :FACT THEN 
OUTPUT “TRUE ; 
TEST FIRST FIRST :QUERY = “? 
IFTRUE IF NOT VALUE? FIRST :QUERY FIRST 
“FACT :VARS THEN OUTPUT “FALSE 
[FFALSE IF NOT ( FIRST :QUERY = FIRST :FACT ) 
_ THEN OUTPUT “FALSE 
OUTPUT MATCH? BUTFIRST :QUERY BUTFIRST 
“FACT se 
END 


To see how VALUE? works, let’s first consider the 
case where the inputs are ?/MPLEMENT, AXE, and 
[?MAN ZACHARIAH]. VALUE? tries to ascertain 
whether the variable ?IMPLEMENT could have the 
value AXE. There are _ three possibilities: 


~?IMPLEMENT already has a value, which is not AXE, 


and VALUE? outputs FALSE; ?IMPLEMENT already 
has the value AXE, and VALUE outputs TRUE; or 
?IMPLEMENT does not have a value, so it is given 
the value AXE, and this information is added to 
VARS and TRUE is output. 


TO VALUE? :NAME :VALUE :VLIST 
IF EMPTY? :VLIST THEN MAKE “VARS LPUT LIST 
“NAME :VALUE :VARS OUTPUT “TRUE 
TEST :NAME = FIRST FIRST :VLIST 
IFTRUE IF :VALUE = LAST FIRST :VLIST THEN 
OUTPUT “TRUE ELSE OUTPUT “FALSE 
OUTPUT VALUE? :NAME :VALUE BUTFIRST 
“VLIST | 
END 


_ PRINTL simply arranges for the components of ANS 


to be printed out below each other. 








TO PRINTL :LIST 
IF EMPTY? :LIST STOP | 
PRINT FIRST :LIST 
PRINTL BUTFIRST :LIST 
END 


MORE COMPLEX ENQUIRIES 


Our investigation will not go far, however, unless . 


we can ask more complex questions, such as “What 
implement killed Zachariah, and who owns such 
an implement?’ In Loco, this reads: 


WHICH [[KILLED ZACHARIAH ?IMPLEMENT]| 
[OWNS ?SUSPECT ?IMPLEMENT]] 


WHICH now takes a list of queries as input and the 
values found will be those that make all of the 
queries true. If you then wish to ask a single query 
with this new form of WHICH the syntax we use is: 


WHICH [[OWNS ?ANY KNIFE]] 


We need make only minor alterations to these 
procedures: 


TO WHICH :QUERIES 
FIND :QUERIES :DATABASE 
PRINT [NO (MORE) ANSWERS] . 
END 


TO FIND :QUERIES :DATA 
_ MAKE “VARS [] 
MAKE “ANS [] 
COMPARE :QUERIES :DATA 
PRINTL :ANS 
END 


COMPARE now has a rather difficult job to do. Let’s 
take [[KILLED ZACHARIAH ?IMPLEMENT][OWNS 
2SUSPECT ?IMPLEMENT]] as an example input. 


_ COMPARE goes through the database, one fact at a 


time, to find a match for the first query, and ends 
up matching ?IMPLEMENT with AXE. The routine 
then considers the second query ([OWNS 
2SUSPECT ?IMPLEMENT]), starting again from the 
beginning of the database. A match is found for 
the second condition, with the value of 
?IMPLEMENT as AXE and ?SUSPECT as MATTHEW. 
There are no more queries, so this is a possible 
solution. | 

But we have not finished yet; there may be other 
values that satisfy the second query, while keeping 
?IMPLEMENT as AXE. So COMPARE now proceeds 


_ through the database from the point it left off, and 
indeed finds a second solution with ?SUSPECT as 


JOSHUA. Of course, the procedure does not stop 
there, but continues searching the DATABASE. ‘This 
time it reaches the end without finding any new 
matching values. 

It is possible, however, that there is another 
solution to the first query — other than 
?IMPLEMENT as AXE — so we must go back to the 
point where we found that match in the database 
and carry on from there. This process is called 
backtracking. In this case, there are in fact no other 
solutions. : 





THE HOME COMPUTER ADVANCED COURSE 833 











In order not to lose track of where it is up to in its 
assignment of variables, COMPARE puts the present 
values on a stack before MATCH? is used (since 


MATCH? may alter these assignments), and then 
recovers these values afterwards. Here is the full 
procedure: 


TO COMPARE :QUERIES :DATA | 
IF EMPTY? :QUERIES THEN MAKE “ANS FPUT 
‘VARS :ANS STOP 
IF EMPTY? :DATA THEN STOP 
PUSH :VARS 
TEST MATCH? FIRST :QUERIES FIRST :DATA 
IFTRUE COMPARE BUTFIRST :QUERIES 
‘DATABASE 
PULL “VARS 
COMPARE :QUERIES BUTFIRST : DATA 7h. 
END 


In COMPARE we use a stack to keep track of the 
value of VARS, instead of using a temporary 
variable, because COMPARE could call itself 
between the time we want to save the values and 
the time we want to restore them. Therefore, any 
such temporary variable could be overwritten by 


834 THE HOME COMPUTER ADVANCED COURSE 


the next call and the original values lost. ‘The stack 
prevents this from happening. 

PUSH puts a value on ‘top’ of the stack, first 
creating the variable STACK if it does not already 
exist. 


TO PUSH :DATA 

IF NOT THING? :STACK THEN MAKE “STACK (] 
MAKE “STACK FPUT :DATA :STACK 
END — 


PULL takes an item from the stack, and assigns it as 
the value of a variable. 


TO PULL :‘NAME 
MAKE :NAME FIRST :STACK 
MAKE “STACK BUTFIRST :STACK 
END 


~ What we have then are the rudiments of a ‘logic 


programming’ language. That is a language in 
which we simply add facts and rules to a database 
and then query that database by means of logical 
descriptions of the data we require. The best 


_example to date of a logic programming language 


iS PROLOG — but that’s another story! 


DAVID HIGHAM 







































































See CuGE 














ee 














i Senseo 


A special type of electric motor called a 
‘stepper’ motor is used to power the 
Workshop. robot. Stepper motors are 
favoured for computer control because they 
use logic signals to control their speed and 
rotation through discrete steps and are thus 
ideally suited to digital control. 

































































HES 






































































































































2 aE GaU a uuu e inne stan ese anaemia RAR eR Ra i 


The construction of a stepper motor is very 
different from that of a normal motor. To 


























understand the principles of operation we shall 





consider how a simplified stepper motor works. In 
our example (see the diagram headed ‘One Step 
At A Time’) there are two set of windings (‘a’ and 
‘b’) on the stator and two pairs of electromagnetic 
poles on the rotor. In the motors that are used in 
the Workshop robot there are more stator 
windings and more rotor poles than our example 
shows. 3 

The only problem with this convenient form of 
motor control is that the motor consumes as much 
current when stationary as it does when in motion. 
In addition, it cannot be rotated at high speed — 
the different coils cannot energise and de-energise 
quickly .enough. However neither of these 
problems is significant in our robot application. 

Our simplified motor is capable of turning in 
steps of 45° only. Additionally, the direction of 
rotation cannot be controlled. The motors used in 
the robot, however, have four sets of coils that are 
energised in pairs, and the rotor also has many 
more coils than our example shows. This means 
that the direction of rotation may be controlled 
and that the step angle is reduced to 7.5°. To 

















achieve this accurate stepwise rotation, the four 


coils must be energised in a particular and 


complicated sequence as follows: 


Stator Coils Energising Sequence Table 
Step Coil A ColB . CoilC Coil D 


1 on off. on. off 
2 off ON on off 
a off on One on 
4 on off off on 
o on. off on Olt, sete 


This sequence of energisation could be provided 
by software, using four bits of the user port to 
control the four coils. However, this requires some 
complicated programming and Basic could 
certainly not produce these control sequences 
quickly enough. A simpler method is to use a chip 
that has been specially designed for the control of 
stepper motors — the SAA 1027. This contains 
the output drivers and all the logic circuits to 
energise the coils in the correct order to drive a 
stepper motor. 

To rotate the motor through one step, a single 
pulse from the user port is required, with a further 
signal line being needed to determine the direction 
of rotation. The chip contains input stages to 
detect the changes in the three inputs: a pulse to 
rotate the motor one more step, areset input, anda 
direction input that reverses the stator coils 
energising sequence. The inputs are fed into a bi- 
directional counter circuit to produce the correct 
output sequence to the stator coils. 

Finally, the chip also contains a power output 
driver stage that can handle up to 5|00mW. The 
inclusion of this stage means that the motor can be 


THE HOME COMPUTER ADVANCED COURSE 835 





=) 














The Driving Force 
Although the logic of the 
Stepper motor driving chips is 
complex, the principles of 
operation are easily understood. 
In order to turn the rotor the 
Stator coils must be energised 
‘ina certain sequence. A bi- 
directional counter moves 
through this sequence a stage at 
a time in response to a pulse 
signal. The sequence can also 
be stepped through in the 
Opposite direction if the 
direction line input is changed, 
causing the rotor to turn in the 
opposite direction. A third input 
allows the rotor to be reset to its 
position at the beginning of the 
sequence, If required 


connected directly to the chip without the need for 
external power transistors. : 

The complexity of the stepper motor driver chip 
means that the rest of the circuit needed for the 
robot control is very simple indeed. Each motor 
requires one of these chips, to which the motor is 
connected. Unfortunately, the driver chips 
operate at a voltage of about 12 volts, while your 
computer user port operates at five volts. That is, a 
logic zero is zero volts (or thereabouts) and a one is 
five volts. The driver chip inputs require zero volts 
for a zero input and between 7.5 and 12 volts for a 
one. To interface the user port to the driver chips 
we therefore also need a special two-voltage buffer 
chip with the inputs operating on one voltage and 
the outputs on another. This is the 40109 chip that 
is also needed in the circuit. 


pecasoaoasente 
ss Risnnokusisn 
Rae URS Be 
EOC Dan uoaninn re ausnagay 
eenrensuyist & 


pase Bas 8. aenneaaee onc 


a 


Repeat 
ess 
a 


os 
EA 


eats 
aaa 
vogan: 


oe 


ee 
3h SSRN e ae 
SRR REREAD DORON Se Baee 
aa AAR RU RAARa aS Beane sofa 
an 3 : pasa 


Bes e Dlvoguunvanaae 
5 Rei s ae 

ee fe oo mee Te ne 
PER 


a 


Baas 
CRS 
B 


eae 
akan 


re 


Riss 
ie 
ee 


Be peas 
PERS 
Ah: a 


ie 


Rare 


cua 


oR 


Bay 
BRS On 
eS 


y 
: 


Bees 
NaRono 


ie 


ro 





eh 


eae 
RRaou one 


Be 


Past 
eid 


Renee 


ies 
Paonia 
aa 


i 


IER 
She 


3 
= 


soe 


Riis 
Rae 


ae 


ee 


eae 
Se 


Bie 
one 


Es 


eee 
Bes 


eee 
penne 


ao 


a 


5 


spat 
hee 
SaaS 


Soy 


Sih 


ges 


Scr 


me 


SENOS 





KEVIN JONES 


LIZ DIXON 

























MOTOR 1 





















MOTOR 2 












O4F 
CAPACITOR D C 


| SAA 1027 
CAPACITOR DRIVER CHIP 


EARTH 


SAA 1027 
DRIVER CHIP 


D3 
D2 


27092 RESISTOR 
100Q RESISTOR ; 


a. 





8. * 
ee ® D1 
| ° * 40109 BUFFER CHIP 
| . z 
| e ® DO 
| * i +9V 
2 * 
@ @ +12V 
GoD EAE A B  WIRELINKS DILSOCKET 
10002 RESISTOR 2709 RESISTOR 40109 
Gu, sD EvlE AB TRACK BREAKS BUFFER CHIP 
| e%evel ®t: es * C2) ouel 2] , ‘ onsteKenie a 12) 
+5V 
| DO 
D1 
D2 
D3 
| SAA 1027 
DRIVER 
CHIP 
| EARTH 





SAA 1027 pu 
DRIVER CHIP 


| TRACK BREAK 


KEVIN JONES 





The Circuit Diagram 

The circuitry required to drive 
the two stepper motors is 
Straightforward, two SAA 1027 
driver chips being used to 
provide the correct coil 
energising Sequence to each 
motor. As the driver chips 
operate at 12v and user port 
signals from your micro are only 
ov, an additional buffer chip is 
used to isolate the 12v circuitry 
from the computer and translate 
the low voltage user port 
signals into the higher voltage 
signals needed by the driver 
chips. In the next instalment we 
shall show how the circuit board 
connects to the motors and D 
plug and how to make the 
correct connections with the 
computer’s user port 


| THE HOME COMPUTER ADVANCED COURSE 837 








H 
{ 
| 


WUT 
ia 
MIGANN 


SEU 
mee 
Rees 
me 








BYTE THE DUST 





to its conclusion with this instalment. We tie 
up all the loose ends of our debugging 
program, provide an overall view of the flow 
of command within it, and finally code the 








SHES ERS Se Sa EE 


The first task of the main module is to set up th 
interrupt mechanism, which allows us to set 
breakpoints in the program being debugged. 
These transfer control to the debugger and allow 
us to inspect the contents of the registers and 
memory locations. We must then obtain the 
starting address of the program being debugged so 
that control can be passed to it using the S$ 
command. The rest of the main routine involves 
getting commands from the keyboard and 
executing them; control is transferred to the 
program being debugged by the S and G 
commands and returned to the debugger by the 
SWI instructions inserted at the breakpoints. 
Two stages of initialisation for this module were 


- coded in the last instalment (see page 817). The 
_ entry point for interrupts comes immediately after 


the call to this subroutine. The first instruction 
here is to save the stack pointer, S so that it can be 
used to reference the values from the registers 
saved on the stack by the SWI. The next stage is 
command interpretation. We have already 
developed subroutines to perform all the 
commands, so the problem here is to select the 
subroutine appropriate to the command entered. 

It is possible to code this as a set of nested IF 
statements, but we will use the fact that the Get- 


~ Command routine returns an offset into a table of 


command characters to perform these calls using a 
jump table. This is not perhaps the most efficient 
method in this instance, but it is a useful technique 
that is worth looking at. It involves setting up a 
table of addresses for each of the subroutines that 
actually carry out a command. 

The JMP instruction, unlike the branch 
instructions, can use any of the normal addressing 
modes, including indexed and indirect. If we load 


-X with the base address of the table and use the 


offset in B (doubled because this will be a table of 
16-bit addresses, unlike the table of eight-bit 
command letters), then the command: 


JMP [B,X] 


will transfer control to the appropriate subroutine. 
The BSR call is made to the address of this jump 
instruction. As we need to set up this table in 
advance, it is necessary to have another stage of 
initialisation to carry out this operation. 


PROCESS SET-UP-JUMP-TABLE 
Data: 
Jump-Table is a table of eight 16-bit addresses 
CMDB, CMDU, etc. are the start addresses for the 
Subroutines 


Process: 


For each subroutine 

Get start address 

Save start address in Jump-Table 
Endfor 


We must now consider what is to happen at the 
end of the run, when the quit command (Q) is 
issued, although there is, in fact, very little that 
needs doing. It makes sense to leave both the 
debugger and the program intact so that they can 
be re-entered if necessary. | 

The stack should be in the same situation when 
we exit as it was when we started. One solution 
would be to use a separate stack for our program 
by setting S to a new value and then restoring the 
old value. This is often a useful technique, but in 
our situation it may be difficult finding unused 
space in memory, with the debugger sitting on top 
of another program. Another solution is simply to 
increment S by the appropriate amount to lose 
anything that we have left there, but this is also 
difficult because we do not know whether or not 
an interrupt has occurred and the amounts on the 
stack will be different. The simplest solution is to 
save the initial value of S and restore it as the last 
operation of the program. 

The interrupt mechanism, as set up in the 
initialisation procedure, stores three bytes at the 
address given in the SWI vector at SFFFA; we must 
restore this or strange results may occur if the 
operating system uses SWI for its own purposes. 
What we clearly need is a further stage of 
initialisation where we save these values to be 
restored in our quit routine. 


PROCESS SAVE-VALUES 

Data: : | 
Saved is the five bytes to store the saved values 
Stack-Pointer is the current value of S, plus two 
SWI-Vector is found at SFFFA 

Process: 
Save Stack-Pointer in Saved 
Get SWl-Vector 
Save three bytes at SWl-Vector in Saved 


The quit routine (command Q) must simply 
reverse this process and transfer control back to 
the operating system. This can be done in a 
number of ways: the SWI instruction itself can be 
used, after its vector has been reset, or a jump can 
be made to a known entry point in the operating 











system. A jump via the reset vector that resides at Reset-Vector is at SFFFE 
SFFFE is guaranteed to return control to the 


- | Process: 7 3 Program Flow 
a u Id start. 
SPCR RSE usa x jee Restore three bytes from Saved at SWI-Vector These Res rueaen 
-Po; correspond to the debugger 
PROCESS QUIT eee ee program modules. They are 
Data: pee gery | placed in the order in which they 
Saved is the five bytes to store the saved values We are now ready to code the main module. The Winnthoalatene abe 
Stack-Pointer is the current value of S, plus two design has altered slightly from when we first — ¢oloured blue indicate separate 
SWI-Vector is at SFFFA sketched it out, but it remains essentially the same. __ routines being called 
Main Module | Set-Up-Jump-Table Set-Up Interrupt Command Module 









ARNRALERS 





OLS E 





Command G 


THE HOME COMPUTER ADVANCED COURSE 839 


LIZ DIXON 














jz, Subroutine, 
WY redefining register usage. This is not really 


THE MAIN MODULE 


Data: 
Prompt for command entry is ASCII character ‘> 
Command-Offset into table of command characters 
and Jump-Table 
Process: 
Save-Values 
Set-Up-Jump- Table 
Set-Up-Interrupt 
Get Start-Address 
_ Repeat 
Display Prompt 
—Get-Command 
Do-Command 
Indefinitely 


That completes our debugger program. At the 
moment it is rather fragmented, but that is a 
consequence of modular construction. At this 
point we can optimise the code if we wish by 
looking for short cuts. For example, you may find 
that you have had to move a lot of values around to 
make sure that they are in the right registers for a 
so you might make savings by 


advisable unless memory space is very restricted. 
We have defined the same data areas in a number 
of different places, as they are required. ‘There are 
two ways in which you might handle data areas in 
the complete program: you can retain the data 
with the module that uses it, which is theoretically 


the best option; or you can define all the data 


together at the start of the program, which has real 
advantages if you ever want to use a disassembler 
(or even a debugger) on the program. _ 

The debugger should be loaded into any spare 
memory not occupied or used by the program to 
be debugged. It is entered by making ajump to the 
DEBUG entry point, so it is necessary to know this 
address before you start. 

In the later part of this 6809 machine code 
series, we have tried to show the best way in which 
programs are developed, illustrated with a variety 
of techniques. Therefore, the design of our 
debugger program is not necessarily the most 
efficient way to do this particular job. If you have 
followed everything, however, then you should 
have a fairly comprehensive understanding of 
Assembly language programming in general, and 
6809 Assembly in particular. 


Set-Up- Jump-Table ADDD- #2 se care of the 
STABLE Space for 8 two-byte STD X++ Save it 
addresses LDY SFFFA Get Interrupt vector address 
SETUPJ LEAY JTABLE,PCR _ Base address of table in Y LDA Y+ Get first byte to be saved 
LEAX CMDB,PCR Start address of CMDB STA X ‘cae 
subroutine : 
SIX ,Y++ Store it in table Cl oa 
LEAX CMDU,PCR Start address of CMDU ae a ao 
subroutine RTS 
STX ++ Store it in table Command Q 
Ss eS CMDQ —LEAX ~—SAVED,PCR —_Address of Saved 
STX Y++ Store it in table LDY SFFFA SWI-Vector 
LEAX CMDS,PCR Start address of CMDS LDA 2,X First of three bytes 
subroutine STA Yt Restored 
STX Y++ Store it in table LDD 3,X -Other two bytes 
LEAX CMDG,PCR Start address of CMDG STD iv Restored 
subroutine LDS iX Saved Stack-Pointer 
STX ay Store it in table JMP [SFFFE] Indirect jump via reset vector 
LEAX CMDR,PCR a ies of CMDR Main Module 
STIX Y++ Store it in table PROMPT ~ FCB >. 
LEAX CMDM,PCR__ Start address of CMDM STACKP RMB 2 Stack-Pointer for Display- 
: subroutine Registers 
STX tt Storeitintable = DEBUG BSR SAVEIT © Save-Values : 
LEAX CMDQ,PCR Start address of CMDQ BSR SETUPJ Set-Up-Jump-Table 
| subroutine BSR INIT Set-Up-Interrupt and Get 
STX ++ Store it in table Start-Address 
This is the actual jump to the subroutine. We assume that X ENTRY STS STACKP,PCR _ Save Stack-Pointer 
contains the address of JTABLE and B the offset LEAX JTABLE,PCR 
DOCMD JMP [B,X] REPT02 LDA PROMPT,PCR _ Get prompt and 
BSR OUTCH display it 
Save-Values BSR GETCOM Get Command 
SAVED RMB 5 Five bytes to be saved © LSLB | Double offset for 16-bit table 
SAVEIT LEAX SAVED,PCR Get address to save in BSR DOCMD Obey Command 
TFR S,D Move S to D BRA REPT02 Next Command 


840 THE HOME COMPUTER ADVANCED COURSE 










































































Here, courtesy of Oric Products International, we publish the first instalment of the 6502 programmers’ reference card 


DESCRIPTION IMPLIED | IMMED | PAGE ae 


ADD WITH CARRY 69 | 65 
LOGICAL AND : 25 
ARITHMETIC SHIFT LEFT 06 
BRANCH ON CARRY CLEAR 

BRANCH ONCARRY SET 


we ae Bont RELATIVE 
ADDRESS | ADDRESS 


6D 
2D 


BRANCH IF EQUAL TO ZERO 


COMPARE BITS WITH 
~ ACCUMULATOR 


BRANCH ON MINUS 
BRANCH ON NOT EQUAL TO ZERO 
BRANCH ON PLUS 


BREAK 

BRANCH ON OVERFLOW CLEAR 
BRANCH ON OVERFLOW SET 
CLEAR CARRY 

CLEAR DECIMAL 





i 


COs ACS 
CO | C4 

C6 
fee 


CLEAR INTERRUPT MASK 
CLEAR OVERFLOW FLAG 

| COMPARE TO ACCUMULATOR | 
COMPARE TO REG-X / 
COMPARE TO REG-Y¥3 
DECREMENT MEMORY 
DECREMENT REG-X 
DECREMENT REG-Y 
EXCLUSIVE OR ACCUMULATOR 
INCREMENT MEMORY 
INCREMENT REG-X X ‘t 


INCREMENT REG-Y Y 
JUMP TO ADDRESS PC 


2 ED SLD 

S 
xx 
ca 


KA Re OR KO 
ee 























a 
i 
oi 
& 
~¥ 
q 
f 
i 
NE 
Be 
i 
& é 
ae 
s 
ae 
e 
rene 
or 
rs 
: 
: 
4 i 
ni 2 
ce 


3 
fs 
F 
S - 

; 
escent es 
¥ 
? 

aku, F 














F 
¢ 
A " 
ss 
Fe pa 


\ribemeanonenenaia 


es a